package org.rcloud.io.service.impl;

import org.rcloud.io.Utils.ResultVo;
import org.rcloud.io.mapper.SpecialtyMappingMapper;
import org.rcloud.io.model.SpecialtyMapping;
import org.rcloud.io.service.SpecialtyMappingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SpecialtyMappingServiceImpl implements SpecialtyMappingService {

    @Autowired
    private SpecialtyMappingMapper smm;

    @Override
    public ResultVo save(SpecialtyMapping specialtyMapping) {
        if (specialtyMapping.equals("") || specialtyMapping == null) {
            return ResultVo.setError("传入数据为空");
        } else {
            Integer aId = specialtyMapping.getbId();
            SpecialtyMapping byAId = null;
            try {
                byAId = smm.findByBId(aId);

            } catch (Exception e) {
                e.printStackTrace();
            }
            try {
                if (byAId != null) {
                    specialtyMapping.setId(byAId.getId());
                    smm.updateByPrimaryKey(specialtyMapping);
                    return ResultVo.setOK("修改成功");
                } else {
                    smm.insert(specialtyMapping);
                    return ResultVo.setOK("添加成功");
                }
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }
}
